/*
* Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
*
* Oracle is a registered trademarks of Oracle Corporation and/or its affiliates.
*
* This software is the confidential and proprietary information of
* Oracle Corporation.  You shall not disclose such confidential and
* proprietary information and shall use it only in accordance with the
* terms of the license agreement you entered into with Oracle.
*
* This notice may not be removed or altered.
*/
package examples;


import com.tangosol.io.pof.PofReader;
import com.tangosol.io.pof.PofWriter;
import com.tangosol.io.pof.PortableObject;
import com.tangosol.util.Base;

import java.io.IOException;


/**
* The ContactInfo class encapsulates common contact information for a person.
*/
public class ContactInfo
        extends Base
        implements PortableObject
    {
    // ----- constructors ---------------------------------------------------

    /**
    * Default constructor (necessary for PortableObject implementation).
    */
    public ContactInfo()
        {
        }

    /**
    * Create a new ContactInfo object.
    *
    * @param sName    the name of the person
    * @param sStreet  the street on which the person lives
    * @param sCity    the city where the person lives
    * @param sState   the state where the person lives
    * @param sZip     the zip code of the city where the person lives
    */
    public ContactInfo(String sName, String sStreet, String sCity,
            String sState, String sZip)
        {
        setName(sName);
        setStreet(sStreet);
        setCity(sCity);
        setState(sState);
        setZip(sZip);
        }


    // ----- PortableObject interface ---------------------------------------

    /**
    * {@inheritDoc}
    */
    public void readExternal(PofReader reader)
            throws IOException
        {
        setName(reader.readString(0));
        setStreet(reader.readString(1));
        setCity(reader.readString(2));
        setState(reader.readString(3));
        setZip(reader.readString(4));
        }

    /**
    * {@inheritDoc}
    */
    public void writeExternal(PofWriter writer)
            throws IOException
        {
        writer.writeString(0, getName());
        writer.writeString(1, getStreet());
        writer.writeString(2, getCity());
        writer.writeString(3, getState());
        writer.writeString(4, getZip());
        }


    // ----- accessors ------------------------------------------------------

    /**
    * Determine the name of the person for which this ContactInfo object
    * contains contact information.
    *
    * @return the person's name
    */
    public String getName()
        {
        return m_sName;
        }

    /**
    * Configure the name of the person for which this ContactInfo object
    * contains contact information.
    *
    * @param sName  the person's name
    */
    public void setName(String sName)
        {
        this.m_sName = sName;
        }

    /**
    * Determine the street on which the person lives.
    *
    * @return the street name
    */
    public String getStreet()
        {
        return m_sStreet;
        }

    /**
    * Configure the street on which the person lives.
    *
    * @param sStreet  the street name
    */
    public void setStreet(String sStreet)
        {
        this.m_sStreet = sStreet;
        }

    /**
    * Determine the city in which the person lives.
    *
    * @return the city name
    */
    public String getCity()
        {
        return m_sCity;
        }

    /**
    * Configure the city in which the person lives.
    *
    * @param sCity  the city name
    */
    public void setCity(String sCity)
        {
        this.m_sCity = sCity;
        }

    /**
    * Determine the state in which the person lives.
    *
    * @return the state name
    */
    public String getState()
        {
        return m_sState;
        }

    /**
    * Configure the state in which the person lives.
    *
    * @param sState  the state name
    */
    public void setState(String sState)
        {
        this.m_sState = sState;
        }

    /**
    * Determine the zip code of the city in which the person lives.
    *
    * @return the zip code
    */
    public String getZip()
        {
        return m_sZip;
        }

    /**
    * Configure the zip code of the city in which the person lives.
    *
    * @param sZip  the city's zip code
    */
    public void setZip(String sZip)
        {
        this.m_sZip = sZip;
        }


    // ----- Object methods -------------------------------------------------

    /**
    * {@inheritDoc}
    */
    public int hashCode()
        {
        String sName = getName();
        return sName == null ? 0 : sName.hashCode();
        }

    /**
    * {@inheritDoc}
    */
    public boolean equals(Object o)
        {
        if (this == o)
            {
            return true;
            }

        if (o instanceof ContactInfo)
            {
            ContactInfo that = (ContactInfo) o;
            return equals(this.getName(),   that.getName())   &&
                   equals(this.getStreet(), that.getStreet()) &&
                   equals(this.getCity(),   that.getCity())   &&
                   equals(this.getState(),  that.getState())  &&
                   equals(this.getZip(),    that.getZip());
            }

        return false;
        }

    /**
    * {@inheritDoc}
    */
    public String toString()
        {
        return "ContactInfo("
                + "Name="     + getName()
                + ", Street=" + getStreet()
                + ", City="   + getCity()
                + ", State="  + getState()
                + ", Zip="    + getZip()
                + ')';
        }


    // ----- data members ---------------------------------------------------

    /**
    * The person's name.
    */
    private String m_sName;

    /**
    * The street on which the person lives.
    */
    private String m_sStreet;

    /**
    * The city in which the person lives.
    */
    private String m_sCity;

    /**
    * The state in which the person lives.
    */
    private String m_sState;

    /**
    * The zip code of the city in which the person lives.
    */
    private String m_sZip;
    }